﻿/* ============================================================================== 
* 功能描述：MenuHelper 
* 创 建 者：张教主 
* 当前版本: V1.0
* 创建日期：2019/2/20 16:51:28 
* ==============================================================================*/


using Newtonsoft.Json;
using System.Collections.Generic;

namespace src.Helper
{
    /// <summary>
    /// 自定义菜单
    /// </summary>
    public partial class MenuHelper
    {
        /// <summary>
        /// 创建菜单
        /// </summary>
        /// <param name="menuStr">菜单json</param>
        /// <param name="accessToken">accesstoken</param>
        /// <returns></returns>
        public static string CreateMenu(string menuStr,string accessToken)
        {
            string postUrl = WCDevUrl.GetCreateMenuUrl(accessToken);
            HttpHelper httpHelper = new HttpHelper();
            return httpHelper.PostStr(menuStr, postUrl);
        }

        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="accessToken">accesstoken</param>
        /// <returns></returns>
        public static string GetMenu(string accessToken)
        {
            string getUrl = WCDevUrl.GetSearchMenuUrl(accessToken);
            HttpHelper httpHelper = new HttpHelper();
            return httpHelper.GetStr(getUrl);
        }

        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="accessToken">accesstoken</param>
        /// <returns></returns>
        public static string DelMenu(string accessToken)
        {
            string getUrl = WCDevUrl.GetDelMenuUrl(accessToken);
            HttpHelper httpHelper = new HttpHelper();
            return httpHelper.GetStr(getUrl);
        }

        /// <summary>
        /// 获取自定义菜单配置接口
        /// </summary>
        /// <param name="accessToken">accesstoken</param>
        /// <returns></returns>
        public static string GetSelfMenuConfig(string accessToken)
        {
            string getUrl = WCDevUrl.GetSelfMenuUrl(accessToken);
            HttpHelper httpHelper = new HttpHelper();
            return httpHelper.GetStr(getUrl);
        }
    }

    /// <summary>
    /// 个性化菜单
    /// </summary>
    public partial class MenuHelper
    {
        /// <summary>
        /// 创建个性化菜单
        /// </summary>
        /// <param name="menuStr">菜单json</param>
        /// <param name="accessToken">accesstoken</param>
        /// <returns></returns>
        public static string CreateConditionalMenu(string menuStr,string accessToken)
        {
            string postUrl = WCDevUrl.GetCreateConditionalUrl(accessToken);
            HttpHelper httpHelper = new HttpHelper();
            string jsonResponse= httpHelper.PostStr(menuStr,postUrl);
            return jsonResponse;
        }

        /// <summary>
        /// 删除个性化菜单
        /// </summary>
        /// <param name="menuId">菜单id 可以通过自定义菜单查询接口获取</param>
        /// <param name="accessToken">accesstoken</param>
        /// <returns></returns>
        public static string DelConditionalMenu(string menuId, string accessToken)
        {
            string postUrl = WCDevUrl.GetDelConditionalUrl(accessToken);
            HttpHelper httpHelper = new HttpHelper();
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("menuid",menuId);
            string postStr = JsonConvert.SerializeObject(dict);
            string jsonResponse = httpHelper.PostStr(postStr, postUrl);
            return jsonResponse;
        }

        /// <summary>
        /// 测试个性化菜单匹配结果
        /// </summary>
        /// <param name="userId">user_id可以是粉丝的OpenID，也可以是粉丝的微信号</param>
        /// <param name="accessToken">accesstoken</param>
        /// <returns></returns>
        public static string TestConditionalMenu(string userId,string accessToken)
        {
            string postUrl = WCDevUrl.GetTestConditionalUrl(accessToken);
            Dictionary<string, string> dict = new Dictionary<string, string>();
            dict.Add("user_id",userId);
            string postStr = JsonConvert.SerializeObject(dict);
            HttpHelper httpHelper = new HttpHelper();
            string jsonResponse = httpHelper.PostStr(postStr, postUrl);
            return jsonResponse;
        }

    }
}
